# Pyramid plot

library(ggpl2)

theme_set(theme_classic())

# Frequency table
df <- as.data.frame(table(mpg$class))
colnames(df) <- c("class", "freq")
pie <- ggplot(df, aes(x = "", y = freq, fill = factor(class))) +
    geom_bar(width = 1, stat = "identity") +
    theme(axis.line = element_blank(),
          plot.title = element_text(hjust = 0.5)) +
    labs(fill = "class", x = NULL, y = NULL,
         title = "Pie chart of class", caption = "mpg")

pie + coord_polar(theta = "y", start = 0)

# Categorical variable
pie2 <- ggplot(mpg, aes(x = "", fill = factor(class))) +
    geom_bar(width = 1) +
    theme(axis.line = element_blank(),
          plot.title = element_text(hjust = 0.5)) +
    labs(fill = "class", x = NULL, y = NULL,
         title = "Pie chart of class", caption = "mpg")

pie2 + coord_polar(theta = "y", start = 0)
